<template>
  <div class="l-from-body">
    <!--<el-alert class="l-from-el-alert" title="租户名称，先添加数据连接，与数据连接名称一样" type="warning"></el-alert>-->
    <el-form :model="formData" :rules="rules" size="mini" ref="form" label-width="88px">
      <el-col :span="24">
        <el-form-item label="分类名称" prop="f_Name">
          <el-input v-model="formData.f_Name"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="24">
        <el-form-item label="上级分类" prop="f_ParentId">
          <!--
					<el-select v-model="formData.f_ParentId" placeholder="选择上级" clearable filterable>
					  <el-option v-for="(item,index) in apiArr" :key="item.value" :label="item.label" :value="item.value"></el-option>
					</el-select>
					-->
          <l-tree-select v-model="formData.f_ParentId" :options="lr_apiTree(apiArr)"> </l-tree-select>
        </el-form-item>
      </el-col>

      <el-col :span="24">
        <el-form-item label="描述" prop="f_Description">
          <el-input type="textarea" v-model="formData.f_Description"></el-input>
        </el-form-item>
      </el-col>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.data.datainterfacecategory;
//console.log(api);
export default {
  data() {
    return {
      apiArr: [],
      formData: {
        f_Id: "",
        f_Name: "",
        f_EnabledMark: 1,
        f_Description: "",
        F_CategoryId: "",
      },
      rules: {
        f_Name: [{ required: true, message: "请输入名称" }],
      },
    };
  },
  computed: {},
  created() {
    var _this = this;

    api
      .getList()
      .then((res) => {
        res.data.data.forEach(function (v) {
          v.label = v.f_Name;
          v.value = v.f_Id;
        });
        _this.apiArr = _this.$deepClone(res.data.data);
      })
      .catch(() => {});
  },
  methods: {
    lr_apiTree(data) {
      data = data || [];
      return this.$toTree(data, "f_Id", "f_ParentId", "f_Id", "f_Name");
    },

    resetForm() {
      //this.formData.f_Id = '';
      this.$refs.form && this.$refs.form.resetFields();
    },
    // 校验表单
    validateForm() {
      return this.$formValidateWraper(this.$refs.form);
    },
    setForm(data) {
      //   console.log("设置表单：");
      //   console.log(data);
      this.formData = this.$deepClone(data);
    },
    getForm() {
      //console.log("获取表单：");
      let formData = this.$deepClone(this.formData);
      return formData;
    },
    dblinkChange(e) {
      var _this = this;
      //console.log(e);
      //console.log(this.formData.f_DatabaseLinkId);
      _this.dbArr.forEach(function (v) {
        if (v.value == e) _this.formData.f_Name = v.label;
      });
    },
  },
};
</script>
<style scoped>
.l-from-el-alert {
  margin-bottom: 20px;
}
</style>
